from TestToolsV2.data.ConfigType import configType
from TestToolsV2.data.ConfigPath import configPath
from TestToolsV2.data.ReadConfig import readConfig
from TestToolsV2.model.ExcelReadType import excelReadType
from TestToolsV2.model.Searcher import searcher
from TestToolsV2.common.Mark import mark
from TestToolsV2.view.OpenDialog import openDialog


class dataController:
    """
    所有配置文件管理类，负责数据间的交互操作
    """

    def __init__(self):
        self.read_mainWindown: readConfig = None  # 配置缓存类 MainWindownConfig.json
        self.read_parameters: readConfig = None  # 配置缓存类 ParametersConfig.json
        self.read_reader: readConfig = None  # 配置缓存类 ReaderConfig.json
        self.excelReadType: excelReadType = None  # 表格读取格式类
        self.configPath: configPath = None  # 配置文件地址管理类
        self.searcher: searcher = None  # 缓存表格数据类
        self.mark: mark = None  # 文本标记类
        self.openDialog = openDialog()
        self.__initData()

    def __initData(self):
        self.set_readerConfig()
        self.set_excelReadType()
        self.set_searcher(self.read_mainWindown.get_forkey("defualExcelPath"))
        self.set_mark(self.read_mainWindown.get_forkey("highColor"), self.read_mainWindown.get_forkey("highSize"))

    def set_mark(self, highColor, highSize):
        """
        设置标记器的颜色和字体大小
        """
        self.mark = mark(highColor, highSize)

    def set_readerConfig(self):
        self.configPath = configPath()
        self.read_mainWindown = readConfig(self.configPath.get_config(configType.mainWindown))
        self.read_parameters = readConfig(self.configPath.get_config(configType.parameters))
        self.read_reader = readConfig(self.configPath.get_config(configType.reader))

    def set_excelReadType(self):
        self.excelReadType = excelReadType()
        isOk = self.excelReadType.setExcelReadType(self.read_reader.get_dataDict())
        if not isOk:
            self.openDialog.showMessage(''.join(self.excelReadType.erro))

    def set_searcher(self, excelPath: str):
        self.searcher = searcher(excelPath, self.excelReadType)
